
const Mysql = require('mysql-pro');
const config = require('../config');

const db = new Mysql({
    mysql: {
        host: config.db.host,
        port: config.db.port,
        user: config.db.user,
        password: config.db.password,
        database: config.db.database,
    }
})

db.execute = async (sql) => {
    let res;
    await db.startTransaction();
    if (typeof sql == 'string') {
        res = await db.executeTransaction(sql);
    } else {
        sql.forEach(async (item) => {
            res = await db.executeTransaction(item);
        })
    }
    await db.stopTransaction();

    return res;
}

module.exports = db;
